<html>
<head><meta charset="utf-8"><title>negative impls · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html">negative impls</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="185063252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185063252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185063252">(Jan 07 2020 at 22:47)</a>:</h4>
<p>Hey <span class="user-group-mention" data-user-group-id="1977">@T-lang</span> I'd appreciate feedback on <a href="https://internals.rust-lang.org/t/explicit-negative-impls-to-fix-pin-soundness-hole/11587" target="_blank" title="https://internals.rust-lang.org/t/explicit-negative-impls-to-fix-pin-soundness-hole/11587">this internals thread</a>, specifically on this question I raised there:</p>
<blockquote>
<p>I guess I don't want this thread to necessarily go too far down the design specifics -- at least not yet -- but I'd like to answer the question of "how much of this design we feel we need to do and when".</p>
<p>My inclination, I think, is that we should immediately prototype a way to bar the "evil" DerefMut impl with minimal implications for stable code. Then we can assess how far down the rest of the design path to go -- we don't necessarily have to do it now, though it'd be good to start sketching out what a coherent overall design looks like around traits. (I'd like to be doing that in the wg-traits repository, probably, though till now the focus there has been on implementation questions primarily.)<br>
liked this</p>
</blockquote>



<a name="185063342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185063342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185063342">(Jan 07 2020 at 22:48)</a>:</h4>
<p>Haven't read the internals thread yet -- from the meeting I didn't know if I favored the negative impl or unsafe trait approach, so I'll need to do more reading before I can answer</p>



<a name="185063373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185063373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185063373">(Jan 07 2020 at 22:49)</a>:</h4>
<p><em>prototyping</em> seems sensible though</p>



<a name="185063486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185063486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185063486">(Jan 07 2020 at 22:50)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> had a good post <a href="https://internals.rust-lang.org/t/unsoundness-in-pin/11311/113?u=nikomatsakis" target="_blank" title="https://internals.rust-lang.org/t/unsoundness-in-pin/11311/113?u=nikomatsakis">summarizing a lot of what they said in the meeting</a></p>



<a name="185063539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185063539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185063539">(Jan 07 2020 at 22:51)</a>:</h4>
<p>which also I think does a decent job of sketching what you wanted -- which is, what is the "proof obligation" of someone who invokes <code>new_unchecked</code></p>



<a name="185063557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185063557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185063557">(Jan 07 2020 at 22:51)</a>:</h4>
<p>cool <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="185063579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185063579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185063579">(Jan 07 2020 at 22:51)</a>:</h4>
<p>anyway, I'll take a look at prototyping</p>



<a name="185090930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185090930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185090930">(Jan 08 2020 at 09:04)</a>:</h4>
<p>yes, that post was also specifically a response to <span class="user-mention" data-user-id="126931">@centril</span>'s request for a writeup during the meeting ;)</p>



<a name="185114827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185114827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185114827">(Jan 08 2020 at 14:17)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/68004" target="_blank" title="https://github.com/rust-lang/rust/pull/68004">PR with preliminary support for negative impls</a> is posted.</p>



<a name="185203768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185203768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185203768">(Jan 09 2020 at 11:39)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">trait</span><span class="w"> </span><span class="n">Integer</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">trait</span><span class="w"> </span><span class="n">Float</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">I32</span><span class="p">;</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">F32</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Integer</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">I32</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">Float</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">F32</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">Integer</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">Float</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="c1">// Can I fix the overlapping error with negative impls?</span>
<span class="c1">// impl&lt;T: Integer&gt; !Float for T {}</span>
<span class="c1">// impl&gt;T: Float&gt; !Integer for T {}</span>
</pre></div>



<a name="185203849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185203849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185203849">(Jan 09 2020 at 11:40)</a>:</h4>
<p>Notice that right now, since there can be a <code>T: Integer + Float</code>, the two blanket impls for <code>T: Integer</code> and <code>T: Float</code> overlap.</p>



<a name="185203878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185203878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185203878">(Jan 09 2020 at 11:41)</a>:</h4>
<p>However, if I was able to express that if a <code>T: Integer</code> is always <code>!Float</code> and that a <code>T: Float</code> is always <code>!Integer</code>, then these two blanket impls do not overlap.</p>



<a name="185204025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185204025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185204025">(Jan 09 2020 at 11:43)</a>:</h4>
<p>Can I express that with the negative impls feature?</p>



<a name="185249497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185249497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185249497">(Jan 09 2020 at 20:00)</a>:</h4>
<p>No.</p>



<a name="185249512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185249512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185249512">(Jan 09 2020 at 20:00)</a>:</h4>
<p>Not as implemented, anyway.</p>



<a name="185291674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/185291674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#185291674">(Jan 10 2020 at 08:47)</a>:</h4>
<p>Thanks, that clarifies the scope of the feature for me</p>



<a name="194499383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/negative%20impls/near/194499383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/negative.20impls.html#194499383">(Apr 17 2020 at 21:01)</a>:</h4>
<p>Another observation in support of this: right now the <a href="https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#missing-copy-implementations" title="https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#missing-copy-implementations">https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#missing-copy-implementations</a> lint isn't all that useful, because it's fairly often on purpose.  Being able to have <code>impl !Copy for Foo</code> to explicitly decide against ever offering copy would be a nice improvement.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>